package com.itqf.Service.Exercise.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itqf.Dao.ExerciseMapper;
import com.itqf.Service.Exercise.ExerciseService;
import com.itqf.entity.Exercise;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
//刘龙
@Service
@Transactional
public class ExerciseServiceImpl implements ExerciseService {
    @Resource
    private ExerciseMapper exerciseMapper;
    //模糊加分页
    @Override
    public PageInfo<Exercise> findExercise(int pageindex, int pagesize,String exercisesubject,
                                           int exerciseid,int gradeid) {
        PageHelper.startPage(pageindex,pagesize);
        Map map=new HashMap();
        map.put("exercisesubject",exercisesubject);
        map.put("exerciseid",exerciseid);
        map.put("exercisegreadid",gradeid);
        List<Exercise> list=exerciseMapper.findExercise(map);
        return new PageInfo<Exercise>(list);
    }
//查看答案
    @Override
    public Exercise findAnswer(int exerciseid) {
        return exerciseMapper.selectByPrimaryKey(exerciseid);
    }
//收藏
    @Override
    public int saveExercise(int exerciseid) {
        Map map=new HashMap();
        map.put("exerciseid",exerciseid);
        return exerciseMapper.saveExercise(map);
    }

    @Override
    public PageInfo<Exercise> mycollection(int pageindex, int pagesize, int exerciseid) {
        PageHelper.startPage(pageindex,pagesize);
        Map map=new HashMap();
        map.put("exerciseid",exerciseid);
        List<Exercise> list=exerciseMapper.mycollection(map);
        return new PageInfo<Exercise>(list);
    }
}
